package com.hy.controller;

import com.hy.common.Result;
import com.hy.entity.Teacher;
import com.hy.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/teachers")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    /**
     * 获取所有教师
     */
    @GetMapping("/teacherlist")
    public Result<List<Teacher>> getAllTeachers() {
        return Result.success(teacherService.getAllTeachers());
    }

    /**
     * 根据ID获取教师
     */
    @GetMapping("/{id}")
    public Result<Teacher> getTeacher(@PathVariable Long id) {
        return Result.success(teacherService.getTeacherById(id));
    }

    /**
     * 添加教师
     */
    @PostMapping("")
    public Result<Boolean> addTeacher(@RequestBody Teacher teacher) {
        return Result.success(teacherService.addTeacher(teacher));
    }

    /**
     * 修改教师
     */
    @PutMapping("/{id}")
    public Result<Boolean> updateTeacher(@PathVariable Long id, @RequestBody Teacher teacher) {
        teacher.setId(id.intValue());
        return Result.success(teacherService.updateTeacher(teacher));
    }

    /**
     * 删除教师
     */
    @DeleteMapping("/{id}")
    public Result<Boolean> deleteTeacher(@PathVariable Long id) {
        return Result.success(teacherService.deleteTeacher(id));
    }

    /**
     * 给教师点赞
     */
    @PostMapping("/likeTeacher")
    public Result<Void> likeTeacher(@RequestBody Teacher teacher) {
        return teacherService.likeTeacher(teacher);
    }

    @GetMapping("/admin/TeacherSelectList")
    public Result<List<Teacher>> getTeachersByLessonId() {
        return Result.success(teacherService.getTeachersByLessonId());
    }
}
